Skip to content

perf: optimize find_in_set in datafusion-functions#23460

Open
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:auto-opt/find_in_set-datafusion-20260710-123200
Open

perf: optimize find_in_set in datafusion-functions#23460
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:auto-opt/find_in_set-datafusion-20260710-123200

Conversation

@andygrove

@andygrove andygrove commented Jul 10, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

N/A

Rationale for this change

Improve performance of existing expression.

What changes are included in this PR?

Replace per-row O(set_len) linear scan in find_in_set's constant-list path with a one-time HashMap lookup (threshold-guarded so short lists keep the linear scan), giving O(1) per-row probing for large sets.

Are these changes tested?

Existing tests + new tests

Benchmark (criterion):

  • long_list_256: 95.827% faster (base 1246412ns -> cand 52009ns) - ~24x faster
  • short_list_4: 2.13% faster (base 64343ns -> cand 62972ns)
  • long_list_64: 88.562% faster (base 422083ns -> cand 48276ns)

Are there any user-facing changes?

No

@github-actions github-actions Bot added the functions Changes to functions implementation label Jul 10, 2026
@andygrove andygrove marked this pull request as ready for review July 10, 2026 19:14
@andygrove andygrove added the performance Make DataFusion faster label Jul 10, 2026
// built at most once here rather than per row.
let map: Option<HashMap<&str, usize>> =
(str_list.len() >= FIND_IN_SET_LOOKUP_THRESHOLD).then(|| {
let mut map = HashMap::with_capacity(str_list.len());

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This map is reconstructed for each batch being processed. Would be better to reuse across batches.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into this, and it doesn't seem like it would improve performance much, and would be a significant change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation performance Make DataFusion faster

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant